{extend name='admin@base' /}
{block name="main"}
<style>
.layui-form-label{
	width:200px;
}	
.font_span{
	color : #FF5722;
	margin-right:3px;
}
</style>
<div class="layui-form">
    <div class="layui-form-item">
        <label class="layui-form-label">
            <span class="font_span">*</span>支付宝账号</label>
        <div class="layui-input-block">
            <input type="text" name="APPID" required lay-verify="app_id" placeholder="请输入支付宝账号" value="{$info['value']['appid']}" autocomplete="off" class="layui-input" style="width:50%">
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label">
            <span class="font_span">*</span>合作者身份ID</label>
        <div class="layui-input-block">
            <input type="text" name="parentid" required lay-verify="parentid" placeholder="请输入合作者身份ID" value="{$info['value']['parentid']}" autocomplete="off" class="layui-input" style="width:50%">
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label">
            <span class="font_span">*</span>安全校验码</label>
        <div class="layui-input-block">
            <input type="text" name="key" required lay-verify="key" placeholder="请输入密钥key" value="{$info['value']['key']}" autocomplete="off" class="layui-input" style="width:50%">
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label">是否启用支付</label>
        <div class="layui-input-block">
            <input type="checkbox" required name="apiclient_status" value="1" lay-skin="switch" lay-filter="switchTest" {if condition='$info.status' eq 1}checked{/if}></div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label">是否启用退款</label>
        <div class="layui-input-block">
            <input type="checkbox" required name="refund_is_use" value="1" lay-skin="switch" lay-filter="switchTest" {if condition='$info.value.refund_is_use' eq 1}checked{/if}>
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label">是否启用转账</label>
        <div class="layui-input-block">
            <input type="checkbox" required name="transfer_is_use" value="1" lay-skin="switch" lay-filter="switchTest" {if condition='$info.value.transfer_is_use' eq 1}checked{/if}>
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label"></label>
        <div class="layui-input-block">
            <button class="layui-btn" lay-submit lay-filter="savePay">保存</button>
            <a href="javascript:history.back(-1);" class="layui-btn layui-btn-primary">返回</a>
        </div>
    </div>
</div>
<script>
layui.use('form', function() {
    var form = layui.form;
	var repeat_flag = false;//防重复标识
    form.on('submit(savePay)',
    function(data) {
        var value = {};
            value.appid = data.field.APPID;
            value.parentid = data.field.parentid;
            value.key = data.field.key;
            value.refund_is_use = data.field.refund_is_use || 0;
            value.transfer_is_use = data.field.transfer_is_use || 0;
        var apiclient_status = data.field.apiclient_status || 0;
        if(repeat_flag) return;
		repeat_flag = true;
        $.ajax({
            type: "post",
            url: '{:addon_url("PayAlipay://admin/payconfig/index")}',
            data: {
                name : '{$name}',
                value : JSON.stringify(value),
                status : apiclient_status
            },
            dataType : "JSON",
            success: function(res) {
				repeat_flag = false;
                layer.msg(res.message);
            }
        });
    });
    
    form.verify({
        app_id: function(value, item) {
            if (value == '') {
                return '请输入支付宝账号';
            }
        },
        parentid: function(value, item) {
            if (value == '') {
                return '请输入合作者身份id';
            }
        },
        key: function(value, item) {
            if (value == '') {
                return '请输入安全校验码';
            }
        }
    });
});

$("#resets").click(function() {
    $(":input[type='text']").attr('value', '');
    $(":input[type='checkbox']").prop('checked', false).removeAttr('checked');
});
</script>
{/block} 